package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/description/
 * @create 2025/9/5 16:51
 * @since JDK17
 */

public class Solution78 {
    public int crackNumber(int ciphertext) {
        if (ciphertext < 10) {
            return 1;
        }
        int[] nums = new int[15];
        int n = 0;
        while (ciphertext != 0) {
            nums[n++] = ciphertext % 10;
            ciphertext /= 10;
        }
        for (int i = 0, j = n - 1; i < j; i++, j--) {
            int t = nums[i];
            nums[i] = nums[j];
            nums[j] = t;
        }
        int[] dp = new int[n + 1];
        dp[1] = dp[0] = 1;
        for (int i = 2; i <= n; i++) {
            if (nums[i - 2] != 0 && nums[i - 1] + nums[i - 2] * 10 < 26) {
                dp[i] = dp[i - 2];
            }
            dp[i] += dp[i - 1];
        }

        return dp[n];
    }
}
